<template>
	<view>
		<u-navbar  >
			<view class="slot-wrap">
				<input type="text"  class="input" placeholder="输入搜索关键字" v-model="text"/>
			</view>
			<text slot="right" style="padding-right: 30rpx ;font-size: 26rpx;" @click="navto">搜索</text>
		</u-navbar>
		<view class="content">
			<view class="stitle"><text>搜索历史</text><u-icon name="trash"></u-icon></view>
			<view class="lisbox">
				<text v-for="(item,index) in list" :key="index" @click="to(item)">{{item}}</text>
			</view>
			<!-- <view class="stitle">搜索发现</view>
			<view class="search_item">
				<view style="width: 50%;height: 50rpx;">
					华为
				</view>
				<view style="width: 50%;height: 50rpx;">
					华为
				</view>
				<view style="width: 50%;height: 50rpx;">
					华为京东自营旗舰店
				</view>
				<view style="width: 50%;height: 50rpx;">
					华为京东自营旗舰店
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				text:'',
				list:[]
			}
		},
		onShow() {
			if(uni.getStorageSync("search")){
				this.list=uni.getStorageSync("search")
			}
		},
		methods: {
			navto(){
				if(this.text.trim()!=''){
					let arr=[]
					if(uni.getStorageSync("search")){
						arr=uni.getStorageSync("search")
					}
					console.log(arr)
					arr.unshift(this.text.trim())
					if(arr.length>20){
						arr.splice(arr.length-1,1)
					}
					uni.setStorageSync("search",arr)
					uni.navigateTo({
						url:"/pages/search/searchShop?text="+this.text
					})
				}
			},
			to(e){
				uni.navigateTo({
					url:"/pages/search/searchShop?text="+e
				})
			},
			del(){
				uni.removeStorageSync('search');
				this.list=null
			}
		},
	}
</script>

<style>
	.lisbox{
		padding: 0 30rpx;
	}
	.lisbox>text{
		background: #F6F6F6;
		opacity: 1;
		border-radius: 22px;
		padding: 5rpx 20rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 33px;
		color: #333333;
		opacity: 1;
		margin: 0 10rpx;
	}
	.stitle{
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #333333;
		opacity: 1;
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.stitle>image{
		width:30rpx ;
		height: 30rpx;
	}
	.input{
		width: 578rpx;
		height: 58rpx;
		border: 1px solid #B2B2B2;
		opacity: 1;
		border-radius: 58rpx;
		font-size: 26rpx;
		padding-left: 30rpx;
		box-sizing: border-box;
	}
	.search_item{
		padding: 0 30rpx;
		width: 690rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
	}
</style>
